import count from '@dfeidao/atom-nodejs/db/count';
import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';
import { productid, systemid } from '../../atom/config';
import time from '../../atom/get_data';
interface Message {
	filter: {
		id: string
	};
	page_no: number;
}
// 表名	train_plan
// 标题	培训计划
// 字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
// _id	id	string	50	ⅹ	√
// productid	产品ID	string	50	√	ⅹ
// train_number	培训编号	string	32	√	ⅹ
// training_name	培训名称	string	64	√	ⅹ
// lecturer_number	讲师编号	string	32	√	ⅹ
// lecturer_name	讲师姓名	string	16	√	ⅹ
// train_start_time	培训开始时间	timestamp	50 	√	ⅹ
// training_time	培训结束时间	timestamp	50	√	ⅹ
// training_location	培训地点	string	64	√	ⅹ
// training_content	培训内容	string	512	√	ⅹ
// to_state	进行状态	int	16	√	ⅹ
// take_effect	是否生效	int	16	√	ⅹ
// supposed_come_peo_num	应到人数	int	32	√	ⅹ
// attendance	实到人数	int	32	√	ⅹ
// training_conclusion	培训结论	string	256	√	ⅹ
export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	const { exec, prepare } = await query(action_id, session_id, systemid);
	const { exec: e, prepare: p } = await count(action_id, session_id, systemid);
	prepare('train_plan', ['_id', 'train_number', 'training_name', 'lecturer_number', 'lecturer_name', 'train_start_time', 'training_time', 'training_location', 'training_content', 'to_state', 'take_effect', 'supposed_come_peo_num', 'attendance', 'training_conclusion'], { 'train_number': { $like: '%' + msg.filter.id + '%' } }, 10, msg.page_no, [], []);
	p('train_plan', { '_id': { $like: '%' + msg.filter.id + '%' } });

	const [res1] = await exec();

	const res = res1.map((v) => {
		const c = time(productid, 'train_start_time', v);
		return time(productid, 'training_time', c);

	});
	const ress = await e();
	log(`Service end`);
	return { res, ress };
}
